import java.util.Stack;

class MinStack {
    Stack<Integer> stack1 = new Stack<>();
    Stack<Integer> stack2 = new Stack<>();

    public MinStack() {
    }

    public void push(int val) {
        stack1.push(val);
        if (stack2.isEmpty()) {
            stack2.push(val);
        }else if ( val <= stack2.peek()) {
            stack2.push(val);
        }
    }

    public void pop() {
        int num1 = stack1.peek();
        int num2 = stack2.peek();
        if (num1 == num2) {
            stack1.pop();
            stack2.pop();
        }else {
            stack1.pop();
        }
    }

    public int top() {
        return stack1.peek();
    }

    public int getMin() {
        return stack2.peek();
    }
}